package org.eztouch.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RestController;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger.web.UiConfiguration;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * swagger-ui.html 进行访问
 */
@Configuration
//@EnableWebMvc  //springboot中无需该注解
@EnableSwagger2
@ComponentScan(basePackages = {"org.eztouch"}) //必须存在 扫描的API Controller package name 也可以直接扫描class (basePackageClasses)
public class Swagger2Config {
	@Bean
	public UiConfiguration uiConfig() {
		//Optional swagger-ui ui configuration currently only supports the validation url
		UiConfiguration uiconfig = new UiConfiguration("undefined"); //关闭远程JSON校验
		return uiconfig;
	}
	
	@Bean
	public Docket swaggerSpringMvcPlugin() {
		System.out.println("--------------SwaggerConfig---------------------");
		return new Docket(DocumentationType.SWAGGER_2)
				.select()
				//只扫描RestController注解的类，从而避免出现BasicErrorController的接口
				.apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
				.build()
				.apiInfo(apiInfo());
	}
  
	private ApiInfo apiInfo() {
		return new ApiInfoBuilder()
				.title("系统服务接口文档")
				.description("版权信息：©2017 Copyright. Powered By eztouch.")
//				.contact("eztouch")
//				.license("Apache License Version 2.0")
//				.licenseUrl("https://github.com/springfox/springfox/blob/master/LICENSE")
				.version("1.0")
				.build();
	}
}
